<template>
  <div class="app-container">
    <hq-searchDown ref="hqSearchDown" :select-opts="selectOpts" @click="handleFilter" />
    <div class="filter-container">
      <span v-if="authorityHandle(82)" class="filter-title filter-item">身份所属</span>
      <k-select
        v-if="authorityHandle(82)"
        v-model="listQuery.userType"
        class="filter-item right-item"
        style="width:120px"
        :select-params="dict.type.IDENTITY_TYPE"
        @handleSelectEvent="handleFilter"
      />
      <span class="filter-title filter-item">绑码结果</span>
      <k-select
        v-model="listQuery.bindingStatus"
        class="filter-item right-item"
        style="width:120px"
        :select-params="[{label:'成功',value: 0},{label:'失败',value: 1}]"
        @handleSelectEvent="handleFilter"
      />

      <span class="filter-title filter-item">绑码时间</span>
      <k-date-picker v-model="timeValue" class="filter-item right-item" @hqchang="handleFilter" />
    </div>
    <!--表格相关 -->
    <el-table
      :data="listData"
      border
      fit
      highlight-current-row
      style="width: 100%; border-radius: 8px; margin-top: 30px;"
      :header-cell-style="{ background: '#F6F5FA', color: '#4E4F62' }"
    >
      <el-table-column min-width="60px" type="index" label="序号" align="center" />
      <el-table-column prop="mobile" min-width="100px" label="用户名" align="center" />
      <el-table-column prop="userTypeName" min-width="100px" label="身份所属" align="center" />
      <el-table-column prop="bindingCode" min-width="100px" label="绑定邀请码" align="center" />
      <el-table-column prop="bindingStatusRemark" min-width="100px" label="绑码结果" align="center" />
      <el-table-column prop="bindingTime" min-width="100px" label="绑码时间" align="center" />
    </el-table>
    <pagination
      v-show="totalRows > 0"
      :total="totalRows"
      :page.sync="listQuery.pager.pageNo"
      :limit.sync="listQuery.pager.pageSize"
      @pagination="loadData"
    />

  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { userBindingListBindingData } from '@/api/avatar'
import hqSearchDown from '@/components/hqSearchDown' // 下拉搜索

export default {
  name: 'Extension',
  components: { Pagination, hqSearchDown },
  dicts: ['IDENTITY_TYPE'],
  data() {
    return {
      // 下拉搜索项0
      selectOpts: [
        {
          label: '身份所属',
          value: 'userTypeName'
        },
        {
          label: '用户名',
          rigth: true,
          value: 'mobile'
        }
      ],
      timeValue: '',
      listData: [],
      totalRows: 0, // 分页组件--数据总条数
      listQuery: {
        pager: {
          pageNo: 1,
          pageSize: 10,
          totalRows: '',
          start: ''
        },
        sort: '', // 排序字段 为对应列名,
        direction: '', // 排序 正向(asc)逆向(desc),
        startTime: '', // 最终创建时间",
        endTime: '', // 最早支付时间",
        key: '', // 饰品名称'
        userType: '', // 身份所属',
        iconType: '', // 变更来源',
        useStatus: ''// 头像框状态
      }
    }
  },
  watch: {
    timeValue(val) {
      this.listQuery.startTime = this.timeValue ? this.timeValue[0] : null
      this.listQuery.endTime = this.timeValue ? this.timeValue[1] : null
    }
  },

  created() {
    this.loadData()
  },
  methods: {
    getUserType(userType) {
      let s = ''
      switch (userType) {
        case 2:
          s = '主播'
          break
        case 3:
          s = '玩家'
          break
      }
      return s
    },
    loadData(v) {
      userBindingListBindingData({ ...this.listQuery, ...v }).then(res => {
        const data = res.data
        this.listData = data.rows
        this.totalRows = data.totalRows
      })
    },
    // 搜索查询事件
    // 搜索查询事件
    handleFilter(v, type) {
      if (type !== 1) this.listQuery.pager.pageNo = 1
      this.loadData(v)
    }
  }
}
</script>

<style lang="scss" scoped>
    .filter-container {
      width: 100%;
      height: 48px;
      line-height: 48px;

      .filter-item {
        display: inline-block;
        vertical-align: middle;
        margin-bottom: 10px;
      }
      .right-item{
          margin-right: 10px;
        }
      .kInput {
        position: absolute;
        right: 20px;
      }

      .filter-title {
        height: 48px;
        line-height: 48px;
        font-size: 16px;
        font-weight: 500;
        margin-right: 22px;
        color: #14162E;
      }

      .user-item {
        margin-left: 10px;
        margin-right: 20px;
      }

      .user-status,
      .account-status {
        margin-right: 20px;
      }
    }

</style>
